<template>
	<view class="container">

		<view class="list">
			<view class="item u-flex u-col-center u-row-between">
				<input type="text" v-model="nickname" placeholder="请输入昵称" />
			</view>
		</view>
		<view class="tips">
			点击修改您的昵称
		</view>
		<view class="footer">
			<view class="btn" @click="submit">
				保存
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				avatar: "",
				phone: '',
				nickname: '',
				uid: "",
				userInfo: {},
				http: this.$imgUrl

			}
		},
		onLoad() {

		},
		onShow() {
			this.uid = uni.getStorageSync('uid')
			this.getUserInfo()
		},
		methods: {
			submit() {
				if (!this.nickname) {
					uni.showToast({
						title: '昵称不能为空',
						icon: "none"
					});
					return
				}
				this.$http.post('/app/users/modifyNickname', {
					mid: this.uid,
					nickname: this.nickname
				}).then(res => {
					console.log(res)
					if (res.code == 0) {
						uni.showToast({
							title: '修改成功',
							icon: "none"
						});
						setTimeout(() => {
							uni.navigateBack({
								delta: 1
							})
						}, 2000)

					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},

			getUserInfo() {
				this.$http.post('/app/users/index', {
					mid: this.uid
				}).then(res => {
					console.log(res)
					if (res.code == 0) {
						this.avatar = res.data.avatar
						this.phone = res.data.phone
						this.nickname = res.data.nickname

					} else {
						uni.showToast({
							title: res.msg,
							icon: "none"
						});
					}
				}).catch(err => {
					console.log('表单错误信息：', err);
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.container {
		padding: 80rpx 20rpx 150rpx;

		.tips {

			height: 40rpx;
			line-height: 40rpx;
			
			font-size: 28rpx;
			color: #B5B5BB;
			text-align: left;
			margin-top: 30rpx;
		}

		.footer {
			.btn {
				width: 100%;
				height: 80rpx;
				line-height: 80rpx;
				text-align: center;
				background-color: #000;
				color: #fff;
				font-size: 30rpx;
				font-weight: 600;
				border-radius: 40rpx;
			}

			position: fixed;
			left: 0;
			right: 0;
			bottom: 0;
			padding: 20rpx;
			box-shadow: 0rpx -2rpx 4rpx 0rpx rgba(0, 0, 0, 0.2);
			background-color: #fff;
		}

		.list {
			padding: 0 20rpx;
			background-color: #fff;
			border-radius: 20rpx;

			.item {
				height: 120rpx;
				line-height: 120rpx;
				font-size: 28rpx;
				color: #000;

				input {
					font-size: 28rpx;
					color: #000;
					height: 120rpx;
					line-height: 120rpx;
					padding: 0 20rpx;
				}

				.l {
					width: 150rpx;
				}

				.r {
					flex: 1;
					width: 1rpx;
					text-align: right;

					text {}

					image {
						width: 12rpx;
						height: 20rpx;
						margin-left: 10rpx;
					}
				}
			}
		}

		.upload {
			position: relative;
			width: 240rpx;
			height: 240rpx;
			border-radius: 120rpx;
			border: 4rpx solid #FFFFFF;
			margin: 0 auto 106rpx;

			image {
				width: 100%;
				height: 100%;
				overflow: hidden;
				border-radius: 50%;
			}

			.edit {
				position: absolute;
				bottom: 0;
				right: 0;
				width: 60rpx;
				height: 60rpx;
			}
		}
	}
</style>